import apis from '../../http/api/apis'

export default {
    namespaced: true,
    // 公共data  只能mutations修改
    state: {
        ordersAllData: [{
            claimsId: "",
            customersId: "",
            endTime: "",
            productsId: "",
            salesId: "",
            startTime: "",
            state: "",
            termination: "",
            _id: ""
        }],
    },
    // 计算属性
    getters: {

    },
    // 方法
    mutations: {
        getOrdersList(state, data) {
            state.ordersAllData = data
        },

    },
    // 异步方法
    actions: {

        // 获取所有订单信息
        async getOrdersList(state, value) {
            const {
                data
<<<<<<< HEAD
            } = await apis.ordersManage.getOrdersList({ salesId: value })
            console.log(data);
=======
            } = await apis.ordersManage.getOrdersList({
                salesId: value
            })
>>>>>>> 7be5ca5f2ef6a641d0e7195aaf137961f6353002
            if (data.code) {
                state.commit('getOrdersList', data.data)
            }
        },
        // 新增订单
        async postOrdersAdd(state, value) {
            return  await apis.ordersManage.postOrdersAdd(value)
        },
        // 修改订单 退保
        async applyOrders(state, value) {
            return await apis.ordersManage.applyOrders(value)
        },
        // 删除订单
        async deleteOrders(state, value) {
            return await apis.ordersManage.deleteOrders(value)
        },
        //获取单个订单信息
        async getOrdersOne(state, value) {
           return await apis.ordersManage.getOrdersOne(value)
          
        },
        // 按客户/产品查询订单
        async getOrdersListId(state, value) {
            const{data}= await apis.ordersManage.getOrdersListId(value)
            if (data.code) {
                state.commit('getOrdersList', data.data)
            }
        },
        // 按销售员查询订单
        async getOrdersSalesIdList(state, value) {
            const{data}= await apis.ordersManage.getOrdersSalesIdList(value)
            console.log(data);
            if (data.code) {
                state.commit('getOrdersList', data.data)
            }
        },

    },
    // 模块

}